package org.example;

import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.IOUtils;
import java.io.*;
import java.net.URL;
public class HDFSApi_3 {
    static{
        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
    }
    /**
     * 主函数
     */
    public static void main(String[] args) throws Exception {
        String remoteFilePath = "hdfs://node1:8020/words.txt"; // HDFS 文件
        InputStream in = null;
        try{
            /* 通过 URL 对象打开数据流，从中读取数据 */
            in = new URL(remoteFilePath).openStream();
            IOUtils.copyBytes(in,System.out,4096,false);
            System.out.println("读取成功！");
        } finally{
            IOUtils.closeStream(in);
            System.out.println("读取结束！");
        }
    }
}
